﻿<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
    <title>渠道报告</title>
    <style>
        .pagecontent {
            width: 100%;
            height: 100%;
            padding: 20px;
            box-sizing: border-box;
        }

        .pagecontent .toolarea {
            display: block;
            line-height: 40px;
        }

        .toolarea .spanstate {
            font-size: 14px;
            cursor: pointer;
            padding-left: 10px;
            padding-right: 10px;
        }

        .toolarea input[type=button] {
            display: inline-block;
            padding: 4px;
            border: 0;
            background-color: rgb(63, 218, 89);
            border-radius: 2px;
            cursor: pointer;
            padding-left: 20px;
            padding-right: 20px;
            color: white;
        }

        .toolarea .selected {
            font-weight: bold;
        }

        #chartarea {
            width: 100%;
            height: 500px;
            position: relative;
            margin: auto;
        }
        .selectChannel {
            line-height: 30px;
            width: 200px;
            text-align: center;
            height: 30px;
        }
    </style>
</head>

<body>


    <div class="pagecontent">
        <div class="toolarea">

            <select class="selectChannel">
                <option value="0">所有渠道</option>
            </select>

            <input type="text" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:00:00'})" id="datemax"
                class="input-text Wdate datestart" style="width:180px;">
            <span>-</span>
            <input type="text" value="" onClick="WdatePicker({el:this,dateFmt:'yyyy-MM-dd HH:00:00'})" id="datemax"
                class="input-text Wdate dateend" style="width:180px;">
            <input type="button" value="查询" onclick="_funcload();">
        </div>
        <!-- 工具选择区域 -->
        <div id="chartarea">

        </div>
    </div>


    <!--_footer 作为公共模版分离出去-->
    <script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layer/2.4/layer.js"></script>
    <script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="../lib/jquery.contextmenu/jquery.contextmenu.r2.js"></script>
    <script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script>
    <!--/_footer 作为公共模版分离出去-->
    <!--请在下方写此页面业务相关的脚本-->
    <!-- <script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> -->


    <script src="../lib/api.js"></script>
    <!-- <link href="../lib/page.min.css" rel="stylesheet" />
    <script src="../lib/page.min.js"></script> -->

    <script src="echarts.min.js"></script>

    <script>

        // var pageobject = null;

        var issecond = true;
        var containername = "dockertest";

        var linuxid = 0;

        var comtypes = [];

        function _showpagedata(datas) {

            var option = {
                title: {
                    text: ''
                },
                tooltip: {
                    trigger: 'axis'
                    // trigger: 'axis',
                    // formatter: function (params) {
                    //     var relVal = params[0].name;
                    //     for (var i = 0, l = params.length; i < l; i++) {
                    //         relVal += '<br/>' + params[i].marker + params[i].seriesName + "&nbsp;" + params[i].value + "MB"
                    //     }
                    //     return relVal;
                    // }
                },
                toolbox: {
                    show: true,
                    feature: {
                        magicType: { show: true, type: ['stack', 'tiled'] },
                        saveAsImage: { show: true }
                    }
                },
                legend: {
                    data: []
                },
                xAxis: {
                    data: []
                },
                yAxis: [],
                series: []
            };

            // data: ['新单', '退款单', '退款金额', '完成单']

            // var array1 = new Array();
            // var array2 = new Array();
            // var array3 = new Array();
            // var array4 = new Array();


            option.legend.data = comtypes;

            var data = new Array();

            //x轴数据
            var daydata = [];

            //日期排重
            var daykey = new Array();

            //日期分类数据是否创建
            var daytype = new Array();

            //Y轴 日期分类 数据
            var ytypedata = new Array();

            for (var k = 0; k < datas.length; k++) {
                var item = datas[k];

                if (!daykey.hasOwnProperty(item.dataDate)) {
                    daydata.push(item.dataDate.substr(0, 10));
                    daykey[item.dataDate] = "1";
                }

                var daystr = item.dataDate.substr(0, 10);

                //日期 日期分类 数据

                var darray = JSON.parse(item.dataContext);
                for (var i = 0; i < darray.length; i++) {
                    var one = darray[i];
                    //日期分类 的数据
                    var ytypedatekey = daystr + one.ComplaintName;
                    // console.log("daytype:"+ytypedatekey);
                    if (!ytypedata.hasOwnProperty(ytypedatekey)) {
                        ytypedata[ytypedatekey] = 0;
                    }
                    ytypedata[ytypedatekey] = ytypedata[ytypedatekey] + one.Count;
                }


                var cuskey=daystr+'退款金币';
                    ytypedata[cuskey] = Number(item.totalCoin).toFixed(0);

                    var cuskey1=daystr+'退款金额';
                    ytypedata[cuskey1] = Number(item.totalAmount).toFixed(2);
                // if(data.hasOwnProperty(item.resType)){
                //     //data[item.resType]=data[item.resType]+item.fileSize;
                // }else{
                //     data[item.resType]=[];                 
                // }
                // data[item.resType].push((Number(item.fileSize)/1024/1024).toFixed(2));
            }

            //x轴数据
            for (var k = 0; k < daydata.length; k++) {
                option.xAxis.data.push(daydata[k].toString().substr(0, 10));
            }


            //y轴数据 
            // for(var key in data){
            //     // option.legend.data.push(key.toString());
            //     option.yAxis.push({name:key,type:'value'});


            //     option.series.push({ name: key, type: 'bar', data:data[key]});

            // }

            for (var y in comtypes) {
                var tyname=comtypes[y];
                //添加Y轴数据
                option.yAxis.push({ name: tyname,show:false, type: 'value' });
                var newdata = [];
                //按照日期循环
                for (var d in daydata) {
                    var temkey=daydata[d]+tyname;
                    // console.log("daytype:"+temkey);
                    if(ytypedata.hasOwnProperty(temkey)){
                        newdata.push(ytypedata[temkey]);
                    }else{
                        newdata.push(0);
                    }
                }
                //给这个Y轴数据添加数据
                option.series.push({ name: tyname, type: 'bar', data:newdata});
            }



            //初始化echarts实例
            var myChart = echarts.init(document.getElementById('chartarea'));

            //使用制定的配置项和数据显示图表
            myChart.setOption(option);



            // if(issecond){
            //     setTimeout(() => {
            //         _readpagedata(1);
            //     }, 30000);
            // }

        }


        //页面初始化
        $(window).ready(function () {


            var uidstr = _apigetquery("id");
            if (uidstr != null) {
                containername = (uidstr);
            }

            var linuxstr = _apigetquery("linuxid");
            if (linuxstr != null) {
                linuxid = parseInt(linuxstr);
            }

            // $(".spanstate").on('click', function () {

            //     $(".spanstate").addClass("selected");
            //     var daynow = new Date();
            //     $(".datestart").val(daynow.Format("yyyy-MM-dd HH:00:00"));
            //     var daylater = new Date();
            //     daylater.setTime(daynow.getTime() + 1000 * 3600);
            //     $(".dateend").val(daylater.Format("yyyy-MM-dd HH:00:00"));
            //     issecond = true;
            //     _readpagedata(1);
            // });

            _apiget("/api/sheet/complaintType?page=1&size=2000", false, function (code, obj) {
                // $("[name=sheetInfoId]").empty();
                if (code == 200) {
                    var datas = obj.items;
                    for (var k = 0; k < datas.length; k++) {
                        var item = datas[k];
                        comtypes.push(item.complaintName);
                    }

                    comtypes.push("退款金币");
                    comtypes.push("退款金额");
                }
            });



            _apiget("/api/sheet/sheetChannel?page=1&size=2000", true, function (code, obj) {
                // $("[name=sheetInfoId]").empty();
                if (code == 200) {

                    var datas = obj.items;
                    var htmlStr = "";
                    for (var k = 0; k < datas.length; k++) {
                        var item = datas[k];
                        htmlStr += '<option value="' + item.id + '">' + item.channelName + '</option>';
                    }
                    $(".selectChannel").append(htmlStr);

                }
            });


            var daynow = new Date();
            daynow.setTime(daynow.getTime() - 3600000 * 24 * 31);
            $(".datestart").val(daynow.Format("yyyy-MM-dd 00:00:00"));

            var daylater = new Date();
            daylater.setTime(daylater.getTime() + 1000 * 3600);
            $(".dateend").val(daylater.Format("yyyy-MM-dd 00:00:00"));

            _readpagedata(1);

            $(".inputword").keyup(function (event) {
                if (event.keyCode == 13) {
                    _readpagedata(1);
                }
            });

        });

        function _funcload() {
            issecond = false;
            $(".spanstate").removeClass("selected");
            _readpagedata(1);

        }

        function _readpagedata(page) {
            try {
                var datestart = new Date($(".datestart").val());
                var dateend = new Date($(".dateend").val());

                if (datestart.getTime() >= dateend.getTime()) {

                    layer.msg("开始时间和结束时时间不对，请重新输入！");
                    return;

                }

                _apiget("/api/sheet/channelReport?begindate=" + $(".datestart").val() + "&enddate=" + $(".dateend").val() + "&channelid=" + $(".selectChannel").val(), true, function (code, obj) {
                    if (code == 200) {
                        var datas = obj.items;
                        if (datas.length > 0) {
                            _showpagedata(datas);
                        } else {
                            layer.msg("当前条件没有查询到数据，请选择其他对象或者时间段再试！");
                        }
                        // pageobject.nums = obj.totalCount;
                        // var intid = parseInt(pageobject.nums / pageobject.counts); var less = parseInt(pageobject.nums % pageobject.counts); if (less > 0) { pageobject.pages = intid + 1; } else { pageobject.pages = intid; };
                    }
                });

            } catch (error) {
                layer.msg("时间格式不正确，请重新输入！" + error.message);
            }
            //var inputword = $(".inputword").val();
        }
    </script>
</body>

</html>